package com.its.common.nacos;

import com.alibaba.cloud.nacos.registry.NacosServiceRegistry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;

import java.util.HashMap;

/**
 * @Author xiaxp
 * @Date 12/29/21 17:10
 * @Description
 */
public class NacosLogLevelSetting implements EnvironmentPostProcessor {
    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        addDefaultPropertySource(environment);
    }

    private void addDefaultPropertySource(ConfigurableEnvironment environment) {
        // 自定义修改后添加进去覆盖
        HashMap<String, Object> map = new HashMap<>();
        map.put("logging.level.com.alibaba.nacos", "warn");
        PropertySource source = new MapPropertySource("nacosLogLevelExtend", map);
        environment.getPropertySources().addLast(source);
    }
}
